﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JeanFish.Data.Common
{
    public class DbCommand : System.Data.Common.DbCommand
    {
        private System.Data.Common.DbCommand command;
        private System.Data.Common.DbConnection connection;
        private DbCommandDefinition decoratedCommandDefinition;

        public DbCommand(System.Data.Common.DbCommand command, DbCommandDefinition decoratedCommandDefinition)
        {
            this.command = command;
            this.decoratedCommandDefinition = decoratedCommandDefinition;
        }

        public DbCommandDefinition Definition
        {
            get { return this.decoratedCommandDefinition; }
        }
        protected System.Data.Common.DbCommand Command
        {
            get { return this.command; }
        }
        public override string CommandText
        {
            get
            {
                return this.Command.CommandText;
            }
            set
            {
                this.Command.CommandText = value;
            }
        }

        public override int CommandTimeout
        {
            get
            {
                return this.Command.CommandTimeout;
            }
            set
            {
                this.Command.CommandTimeout = value;
            }
        }

        public override System.Data.CommandType CommandType
        {
            get
            {
                return this.Command.CommandType;
            }
            set
            {
                this.Command.CommandType = value;
            }
        }

        public override bool DesignTimeVisible
        {
            get
            {
                return false;
            }
            set
            {
            }
        }
        public override System.Data.UpdateRowSource UpdatedRowSource
        {
            get
            {
                return this.Command.UpdatedRowSource;
            }
            set
            {
                this.Command.UpdatedRowSource = value;
            }
        }

        protected override System.Data.Common.DbConnection DbConnection
        {
            get
            {
                return this.Connection;
            }
            set
            {
                DbConnection connection = (DbConnection)value;
                if (connection != null)
                {
                    this.connection = connection;
                    this.command.Connection = connection.Connection;
                }
                else
                {
                    this.connection = null;
                    this.command.Connection = null;
                }
            }
        }

        protected override System.Data.Common.DbParameterCollection DbParameterCollection
        {
            get { return this.Command.Parameters; }
        }

        protected override System.Data.Common.DbTransaction DbTransaction
        {
            get
            {
                return this.Command.Transaction;
            }
            set
            {
                this.Command.Transaction = value;
            }
        }

        public override void Cancel()
        {
            this.Command.Cancel();
        }

        public override int ExecuteNonQuery()
        {
            return this.Command.ExecuteNonQuery();
        }
        public override object ExecuteScalar()
        {
            return this.Command.ExecuteScalar();
        }

        public override void Prepare()
        {
            this.Command.Prepare();
        }

        protected override System.Data.Common.DbParameter CreateDbParameter()
        {
            return this.Command.CreateParameter();
        }

        protected override System.Data.Common.DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior)
        {
            return this.Command.ExecuteReader(behavior);
        }
    }
}
